From c1ef3a162622942d7c556c5a4352e626c7bcb28f Mon Sep 17 00:00:00 2001
From: Jean-Louis Dupond <jean-louis@dupond.be>
Date: Tue, 8 May 2012 14:44:16 +0200
Subject: [PATCH] Disconnect signal handler after disconnect

---
 remmina-plugins/rdp/rdp_event.c  |   10 ++++++++--
 remmina-plugins/rdp/rdp_plugin.h |    1 +
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/remmina-plugins/rdp/rdp_event.c b/remmina-plugins/rdp/rdp_event.c
index a936fb1..2c050c6 100644
--- a/remmina-plugins/rdp/rdp_event.c
+++ b/remmina-plugins/rdp/rdp_event.c
@@ -523,8 +523,7 @@ void remmina_rdp_event_init(RemminaProtocolWidget* gp)
 	if (!remmina_plugin_service->file_get_int(remminafile, "disableclipboard", FALSE))
 	{
 		clipboard = gtk_widget_get_clipboard(rfi->drawing_area, GDK_SELECTION_CLIPBOARD);
-		g_signal_connect(clipboard, "owner-change",
-			G_CALLBACK(remmina_rdp_event_on_clipboard), gp);
+		rfi->clipboard_handler = g_signal_connect(clipboard, "owner-change", G_CALLBACK(remmina_rdp_event_on_clipboard), gp);
 	}
 
 	rfi->pressed_keys = g_array_new(FALSE, TRUE, sizeof (gint));
@@ -575,6 +574,13 @@ void remmina_rdp_event_uninit(RemminaProtocolWidget* gp)
 
 	rfi = GET_DATA(gp);
 
+
+	/* unregister the clipboard monitor */
+	if (rfi->clipboard_handler)
+	{
+		g_signal_handler_disconnect(G_OBJECT(gtk_widget_get_clipboard(rfi->drawing_area, GDK_SELECTION_CLIPBOARD)), rfi->clipboard_handler);
+		rfi->clipboard_handler = NULL;
+	}
 	if (rfi->scale_handler)
 	{
 		g_source_remove(rfi->scale_handler);
diff --git a/remmina-plugins/rdp/rdp_plugin.h b/remmina-plugins/rdp/rdp_plugin.h
index ff66906..08b8891 100644
--- a/remmina-plugins/rdp/rdp_plugin.h
+++ b/remmina-plugins/rdp/rdp_plugin.h
@@ -134,6 +134,7 @@ struct rf_context
 	GAsyncQueue* event_queue;
 	gint event_pipe[2];
 
+	gint clipboard_handler;
 	gint clipboard_wait;
 	uint32 requested_format;
 };
-- 
1.7.10

